package com.jp.knowledge.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.my.model.ColleagueAuditModel;
import com.jp.knowledge.util.ImageLoadUtil;
import com.jp.knowledge.util.TimeUtil;

import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/4/14.
 */

public class ReviewOrganizeAdapter extends RecycleVAdapter<ColleagueAuditModel> implements View.OnClickListener {

    public ReviewOrganizeAdapter(Context context, @NonNull List<ColleagueAuditModel> list) {
        super(context, list);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_review_organize;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        ColleagueAuditModel data = getData(position);
        ImageLoadUtil.load(mContext,
                data.getUserIcon(),
                holder.getImageView(R.id.icon),
                R.mipmap.ic_my_header
        );
        setTextView(holder.getTextView(R.id.name), data.getUserName());
        setTextView(holder.getTextView(R.id.phone), data.getUserMobile());
        setTextView(holder.getTextView(R.id.time), TimeUtil.friendly_time(data.getApplyTime()));
        TextView reViewBtn = holder.get(R.id.reviewBtn);
        reViewBtn.setTag(position);
        if (data.getAuditState() == 2){
            reViewBtn.setText("已拒绝");
            reViewBtn.setTextColor(mContext.getResources().getColor(R.color.font_gray));
//            reViewBtn.setBackground(mContext.getResources().getDrawable(R.drawable.search_btn_gray));
            reViewBtn.setBackground(null);
            reViewBtn.setOnClickListener(null);
            reViewBtn.setClickable(false);
        } else{
            reViewBtn.setText("审核");
            reViewBtn.setTextColor(mContext.getResources().getColor(R.color.theme_color));
            reViewBtn.setBackground(mContext.getResources().getDrawable(R.drawable.search_btn_blue));
            reViewBtn.setClickable(true);
            reViewBtn.setOnClickListener(this);
        }
    }

    private void setTextView(TextView textView, String str){
        if(str == null || str.trim().length() == 0) {
            textView.setVisibility(View.GONE);
        } else{
            textView.setVisibility(View.VISIBLE);
            textView.setText(str);
        }
    }

    @Override
    public void onClick(View v) {
        int position = (int)v.getTag();
        if(this.reviewBtnClickListener != null)
            this.reviewBtnClickListener.onBtnClick(position);
    }

    private ReviewBtnClickListener reviewBtnClickListener;
    public void setReviewBtnClickListener(ReviewBtnClickListener listener){
        this.reviewBtnClickListener = listener;
    }
    public interface ReviewBtnClickListener{
        void onBtnClick(int position);
    }
}
